﻿using System;
using System.Linq;
using System.Windows;
using GameLogic.Controls;

namespace GameLogic.Logic
{
    public class CollisionTrigger : GameLoopTrigger<FrameworkElement>
    {
        protected override void OnGameLoopInitialized()
        {
            this.GameLoop.Collision += this.OnGameLoopCollision;
        }

        private void OnGameLoopCollision(object sender, CollisionEventArgs e)
        {
            if (e.CollisionInformation.Any(collisionInfo => 
                object.ReferenceEquals(this.Source, collisionInfo.CollidingElement)
                || object.ReferenceEquals(this.Source, collisionInfo.HitElement)))
            {
                this.InvokeActions(EventArgs.Empty);
            }
        }
    }
}